cmake_minimum_required(VERSION 3.22)
project(bluetoothLyrics)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message("正在编译debug类型的文件")
    set(CMAKE_SYSTEM_PROCESSOR arm)
    set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
    add_definitions(-DDEBUG)
endif()

if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()
# 打印一些编译标志
message("CMAKE_C_FLAGS_DEBUG is ${CMAKE_C_FLAGS_DEBUG}")
message("CMAKE_C_FLAGS_RELEASE is ${CMAKE_C_FLAGS_RELEASE}")
message("CMAKE_C_FLAGS_RELWITHDEBINFO is ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
message("CMAKE_C_FLAGS_MINSIZEREL is ${CMAKE_C_FLAGS_MINSIZEREL}")

message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}")
message("CMAKE_CXX_FLAGS_RELWITHDEBINFO is ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message("CMAKE_CXX_FLAGS_MINSIZEREL is ${CMAKE_CXX_FLAGS_MINSIZEREL}")

# 隐藏所有符号，仅显式导出的符号可见（减少动态库体积）
add_compile_options(-fvisibility=hidden)

# 设置可执行文件输出目录
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
message("CMAKE_RUNTIME_OUTPUT_DIRECTORY is ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # 设置静态库文件输出目录
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # 设置动态库文件输出目录

include_directories(
        /usr/local/include
        /usr/include
        /usr/lib
        /usr/lib/arm-linux-gnueabihf
        /usr/include/freetype2
)
#使用ccache缓存加速编译
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
    set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)

# 查找 ALSA 库
find_package(ALSA REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONC json-c)
pkg_check_modules(CJSON libcjson)
pkg_check_modules(PNG libpng REQUIRED)
pkg_check_modules(GIF libgif REQUIRED)
pkg_check_modules(FREETYPE freetype2 REQUIRED)
pkg_check_modules(CURL libcurl REQUIRED)

# 工程自己的配置
include_directories( .
        inc
)
#自动添加所有cpp
aux_source_directory(src SOURCE_FILE)

add_executable(${PROJECT_NAME}
        main.cpp
        ${SOURCE_FILE}
)

target_link_libraries(${PROJECT_NAME} PUBLIC
        asound
        bluetooth
        systemd
        pthread
        m
        pthread
        ${JSONC_LIBRARIES}
        ${CJSON_LIBRARIES}
        ${PNG_LIBRARIES}
        ${GIF_LIBRARIES}
        ${FREETYPE_LIBRARIES}
        ${CURL_LIBRARIES}
)
message("CMake运行完成，系统是${CMAKE_SYSTEM_NAME}")